<template>
	<div class="front" v-drag>
		<div class="tree-left bg-white">
			<div class="tit">单据列表</div>
			<el-tree :data="treeData" ref="tree" accordion :expand-on-click-node="false" :props="defaultProps" highlight-current @node-click="nodeClick"></el-tree>
		</div>
		<div class="tree-right bg-white">
			<v-menu/>
			<div class="table">
				<v-table/>
			</div>
		</div>
	</div>
</template>
<script>
import menu from './menu'
import table from './table1'
export default {
	components: {
		'v-menu': menu,
		'v-table': table
	},
	data() {
		return {
			treeData: this.$store.state.verifyProcessStore.treeData,
			defaultProps: {
				label: 'name',
				children: 'subList'
			},
			status: this.$store.state.verifyProcessStore.status
		}
	},
	watch: {
		status(newVal) {
			if(newVal[0] === '1') {
				// this.$nextTick(() => this.$refs.tree.setCurrentNode(this.treeData[0]));		//默认选中第一个
			}
		}
	},
	methods: {
		nodeClick(row) {
			if(row['level'] === 0) {
				this.$store.commit('verifyProcessStore/updateTableData', row['children']);		//把当前节点下面的子节点保存到table中
				this.$store.commit('verifyProcessStore/updateIsAdd', true);			//如果点击的是单据节点，允许新增
				this.$store.commit('verifyProcessStore/updateTreeNode', row);		//保存当前操作的节点
				this.$store.commit('verifyProcessStore/updateBillId', row['id']);	//保存单据id
			} else {
				this.$store.commit('verifyProcessStore/updateTableData', []);
				this.$store.commit('verifyProcessStore/updateIsAdd', false);
				this.$store.commit('verifyProcessStore/updateTreeNode');			//清空当前操作的节点
			}
		}
	}
}
</script>